﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="edited_check_admin.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.edited_check_admin" %>

<%@ Import Namespace="DataAccess" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<body>
    <%
        int id = int.Parse(Request.QueryString["id"]);
        int edit_absent = int.Parse(Request.QueryString["absent"]);
        int edit_overtime = int.Parse(Request.QueryString["overtime"]);
        bool overtime = true;
        bool absent = true;
        if (edit_absent == 0)
            absent = false;
        if (edit_overtime == 0)
            overtime = false;
        string checkin = Request.QueryString["checkin"];
        string work_time = "";
        string[] split1 = new string[2];
        split1 = checkin.Split('T');
        DateTime edit_checkin = DateTime.Parse(split1[0] + " " + split1[1]);
        var get_check = new TblCheckManagerController().FetchAll().Where(x => x.Id == id).Single();
        if (absent == false)
        {
            int ca = 0;
            if (edit_checkin.Hour >= 0 && edit_checkin.Hour <= 12)
            {
                ca = 1;
                work_time = "Ca sáng";
            }
            if (edit_checkin.Hour >= 13 && edit_checkin.Hour <= 16)
            {
                ca = 2;
                work_time = "Ca chiều";
            }
            if (edit_checkin.Hour >= 17 && edit_checkin.Hour <= 24)
            {
                ca = 3;
                work_time = "Ca tối";
            }


            if (ca == 1)
                new TblCheckManagerController().Update(id, get_check.ManagerId, edit_checkin, DateTime.Parse(edit_checkin.Year + "-" + edit_checkin.Month + "-" + edit_checkin.Day + " 11:30"), null, false, overtime);
            if (ca == 2)
                new TblCheckManagerController().Update(id, get_check.ManagerId, edit_checkin, DateTime.Parse(edit_checkin.Year + "-" + edit_checkin.Month + "-" + edit_checkin.Day + " 17:00"), null, false, overtime);
            if (ca == 3)
                new TblCheckManagerController().Update(id, get_check.ManagerId, edit_checkin, DateTime.Parse(edit_checkin.Year + "-" + edit_checkin.Month + "-" + edit_checkin.Day + " 21:00"), null, false, overtime);
            if (edit_overtime == 1)
            {
                work_time += " (Tăng ca)";
            }
        }
        else
        {
            work_time = "Vắng";
            if (get_check.Accept == true)
                work_time += " (Có phép)";
            new TblCheckManagerController().Update(id, get_check.ManagerId, edit_checkin, edit_checkin, null, true, false);
        }
        var get_manager = new TblManagerController().FetchAll().Where(x => x.ManagerId == get_check.ManagerId).Single();
        var get_role = new TblManagerRoleController().FetchAll().Where(x => x.RoleId == get_manager.Role).Single();
        var get_edited_check = new TblCheckManagerController().FetchAll().Where(x => x.Id == id).Single();
        
    %>
    <td class="checkinout-img w3-hide-small w3-center">
        <span class="check_id w3-hide"><%=id %></span>
        <img src="../Content/avatar/<%=get_manager.Avatar %>" class="w3-circle" />
    </td>
    <td>
        <span><%=get_manager.FullName %></span><br />
        <span class="w3-text-grey w3-hide-small"><%=get_role.RoleName %></span>
    </td>
    <td><%=work_time %></td>
    <%int get_id = int.Parse(Session["admin_id"].ToString());
      var check_cap = new TblManagerController().FetchAll().Where(x => x.ManagerId == get_id).Single();
      if (check_cap.Captain == true && check_cap.Role == get_manager.Role)
      { %>
    <td>
        <%if (get_edited_check.Accept == false)
          {
              if (get_edited_check.CheckOut != null)
              {%>
        <i title="Xác nhận" class="btn_confirm_check checkinout-option-btn fa fa-check w3-hover-text-teal"></i><%}
              else
              {%><%}
          }
          else
          { %>
        <i title="Đã xác nhận" class="checkinout-option-btn fa fa-check w3-text-teal"></i>
        <%} %>
        <i title="Chỉnh sửa" class="btn_edit_check checkinout-option-btn fa fa-wrench w3-hover-text-teal"></i>
        <i title="Xóa" class="btn_del_check checkinout-option-btn fa fa-trash w3-hover-text-teal"></i>
    </td>
    <%}
      else
      {
          if (get_edited_check.Accept == true)
          {
    %>

    <td>
        <i title="Đã xác nhận" class="checkinout-option-btn fa fa-check w3-text-teal"></i>
    </td>
    <%
          }
      } %>
</body>
</html>
